import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;

public class Servlet1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        String name = request.getParameter("name");
        System.out.println(name);
        String pwd = request.getParameter("pwd");
        System.out.println(pwd);
        if(name.equals("张三")&&pwd.equals("123")){
//            当成立，则返回给浏览器网站首页，实现办法有两个，方法一是把首页文件直接发给浏览器，浏览器接收到解析显示
//                方法二是返回给浏览器一个首页地址，浏览器接收到地址，自动发起访问
            response.sendRedirect("/home.html");
        }else {
            response.setCharacterEncoding("utf-8");
            response.setHeader("Content-Type","text/html;charset=utf-8");
            response.setHeader("Refresh","3;URL=/form.html");
            response.getWriter().write("你输入的用户名或密码不正确，三秒后，自动打开登录页面");
        }

    }
}
